package se.peterbjorkman.android.trafikkamera.infodownload;

import se.peterbjorkman.android.trafikkamera.providers.CameraContentProvider;
import se.peterbjorkman.android.trafikkamera.providers.CameraDefs;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;

public class CameraInserter {

	static void insertCamera(Context context, 
								String id, 
								String name,
								String description, 
								String road,
								int county, 
								double longitude, 
								double latitude, 
								String url,
								String handheldUrl){

		ContentResolver cr = context.getContentResolver();

        ContentValues values = new ContentValues();
        values.put(CameraDefs.NAME,             name);
        values.put(CameraDefs.COUNTY,           county);
        values.put(CameraDefs.ROAD,             road);
        values.put(CameraDefs.DESCRIPTION,      description);
        if (longitude != 0)
        	values.put(CameraDefs.LONGITUDE,        longitude);
        if (latitude != 0)
        	values.put(CameraDefs.LATITUDE,         latitude);
        values.put(CameraDefs.CAMERA_URL_SMALL, handheldUrl);
        values.put(CameraDefs.CAMERA_URL,       url);

        int numberOfRows = cr.update(CameraContentProvider.CONTENT_URI, 
					        		values, 
					        		CameraDefs.EXTID + " = '" + id + "'", 
					        		null);
        
        if (numberOfRows >= 1)
        	return;

        values.put(CameraDefs.EXTID, id);
        
        cr.insert(CameraContentProvider.CONTENT_URI, values);        	
	}
}
